<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="/templates/interna.xhtml">

        <ui:define name="breadcrumb">

            <h:form>

                <p:breadCrumb>
                    <p:menuitem value="#{msg.principal}"/>
                    <p:menuitem value="#{msg.menuCadastros}"/>
                    <p:menuitem value="#{msg.RF003_Consultar_Assuntos}"/>
                </p:breadCrumb>

            </h:form>    

        </ui:define>

        <ui:define name="corpo">

            <h:form id="frm_assuntos">
                
                <style>
                    .info-qtd-registros {
                        float: right !important; 
                        margin-right: 1.5em; 
                        margin-top: 7px; 
                        vertical-align: bottom;
                    }
                </style>                                

                <p:fieldset id="fsAssuntos" legend="#{msg.RF003_Dados_Pesquisa_Assuntos}">
                    
                    <h:panelGrid columns="2">
                        
                        <p:outputLabel for="itAssunto" value="#{msg.RF003_Assunto}: "/>
                        <p:inputText id="itAssunto" value="#{consultarAssunto.parametros.assunto}" style="width: 25em" maxlength="50" onblur="upperCase(this)"/>
                        
                        <p:outputLabel for="itDescricao" value="#{msg.RF003_Descricao}:" />
                        <p:inputTextarea id="itDescricao" value="#{consultarAssunto.parametros.descricao}" style="width: 85em" maxlength="4000" onblur="upperCase(this)" autoResize="false" rows="2"/>
                        
                    </h:panelGrid>
                    
                    <p:spacer width="5" height="20"/>

                    <p:commandButton value="#{msg.pesquisar}"
                                     icon="ui-icon-search"
                                     action="#{consultarAssunto.pesquisar()}"
                                     process="@form"
                                     update="opAssuntos"
                                     style="width: 13em"
                                     oncomplete="dtAssuntos.getPaginator().setPage(0)"/>

                    <p:spacer width="5"/>
                    
                    <p:commandButton value="#{msg.limparCampos}"
                                     action="#{consultarAssunto.limparCampos()}"
                                     icon="ui-icon-clear"
                                     update="@form"
                                     style="width: 13em"/>
                    
                    <p:spacer width="5"/>
                    
                    <p:commandButton value="#{msg.cadastrar}"
                                     action="#{manterAssunto.setup()}"
                                     icon="ui-icon-plus"
                                     style="width: 13em"
                                     ajax="false"/>

                    <p:spacer width="5"/>
                    
                    <p:commandButton value="#{msg.voltar}" 
                                     action="#{consultarAssunto.voltar}" 
                                     ajax="false" 
                                     icon="ui-icon-arrowreturnthick-1-w"
                                     immediate="true"
                                     style="width: 13em"/>	                    
                    
                    <p:outputPanel autoUpdate="true">
                        <h:outputText id="otTotalAssuntos" value="#{msg.RF003_Assuntos_Encontrados}: #{consultarAssunto.qtdAssuntos}" rendered="#{consultarAssunto.qtdAssuntos > 0}" styleClass="texto-negrito-11 info-qtd-registros"/>
                    </p:outputPanel>

                </p:fieldset>
                
                <div class="espacamento"/>

                <p:outputPanel id="opAssuntos">

                    <p:fieldset legend="#{msg.RF003_Lista_Assuntos}" 
                                rendered="#{not empty consultarAssunto.dataModel}">

                        <p:dataTable id="dtAssuntos" 
                                     value="#{consultarAssunto.dataModel}"
                                     var="ass"
                                     rows="#{consultarAssunto.registrosPorPagina}"
                                     rowsPerPageTemplate="#{consultarAssunto.linhasPorPagina}"
                                     paginator="true"
                                     paginatorPosition="bottom"
                                     emptyMessage="#{msg.nenhumRegistroEncontrado}"
                                     widgetVar="dtAssuntos"
                                     lazy="true">

                            <p:column headerText="#{msg.RF003_Assunto}" style="width: 20%" sortBy="#{ass.assunto}">
                                #{ass.assunto}
                            </p:column>

                            <p:column headerText="#{msg.RF003_Descricao}" style="width: 65%" sortBy="#{ass.descricao}">
                                #{ass.descricao}
                            </p:column>

                            <p:column headerText="#{msg.acoes}" style="text-align: center; width: 15%">
                                
                                <p:commandButton icon="ui-icon-search" title="#{msg.RF003_Detalhar_Assunto}" action="#{manterAssunto.detalhar()}" ajax="false">
                                    <f:setPropertyActionListener value="#{ass}" target="#{manterAssunto.assunto}"/>
                                </p:commandButton>
                                
                                <p:commandButton icon="ui-icon-closethick" title="#{msg.RF003_Excluir_Assunto}" oncomplete="dlg_excluir_assunto.show();" ajax="true" rendered="#{loginUsuario.possuiPrivilegio('MANTER_ASSUNTO')}">
                                    <f:setPropertyActionListener value="#{ass}" target="#{consultarAssunto.assunto}"/>
                                </p:commandButton>
                                
                            </p:column>

                        </p:dataTable>                    

                    </p:fieldset>

                </p:outputPanel>

            </h:form>
            
            <ui:include src="/restrito/painel_confirmacao_ajax.xhtml">
                <ui:param name="mensagem" value="#{msg.RF003_Deseja_Realmente_Excluir_Assunto}"/>
                <ui:param name="id" value="dlg_excluir_assunto"/>
                <ui:param name="bean" value="#{consultarAssunto}"/>
                <ui:param name="action" value="excluir"/>
                <ui:param name="update" value=":frm_assuntos:opAssuntos"/>
            </ui:include>
            
        </ui:define>

    </ui:composition>

</html>
